home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / basic / PureBasic_Upd.lha / PureBasic_Update1.60 / PureBasic / Examples / Sources / WildManager.pb < prev   
Encoding:
Text File  |  2000-09-10  |  12.1 KB  |  612 lines

  1. ;
  2. ;
  3. ; ---------->        <------
  4. ; Wild Manager      V1.01
  5. ; ------------>    <--------
  6. ;
  7. ; © 1999 - Fantaisie Software - Coded by AlphaSND
  8. ;       
  9. ;
  10. ; Description: Preference front-end for the WILD 3D package from 'Pyper'
  11. ;     
  12. ;
  13. ; NOTE:
  14. ; -----
  15. ;
  16. ; A String in a linked list must not be to NULL for the listview, else
  17. ; we got an enforcer hit (AmigaOS 'bug') !
  18. ;
  19. ;
  20.  
  21. WBStartup()
  22.  
  23. InitScreen(0)
  24. InitWindow(0)
  25. InitGadget(0)
  26. InitFile  (0)
  27.  
  28. If InitRequester() = 0
  29.   End
  30. EndIf
  31.  
  32. *TagList = InitTagList(10)  ; Note you can use TagListID() but using a variable is smaller/faster
  33.  
  34. Mode.s
  35.  
  36. Structure PBScreenInfo
  37.   DisplayID.l     ; Display mode ID
  38.   Width.l         ; Width of display in pixels
  39.   Height.l        ; Height of display in pixels
  40.   Depth.w         ; Number of bit-planes of display
  41.   OverscanType.w  ; Type of overscan of display
  42.   AutoScroll.b
  43. EndStructure
  44.  
  45.  
  46. Structure NLVList
  47.   Pad.w
  48.   Item.s
  49.   Command.s
  50.   Processors.b
  51.   Rendering.b
  52.   Warp3D.b
  53.   Width.w
  54.   Height.w
  55.   ScreenID.l
  56.   Changed.b
  57.   AGA.b
  58. EndStructure
  59.  
  60. NewList PL.NLVList()
  61.  
  62. ;
  63. ; Read pref file..
  64. ;
  65. ;LoadPref
  66.  
  67. If ReadFile(0, "PROGDIR:WildManager.pref")
  68.  
  69.   a$ = ReadString()
  70.   If a$ = "WildManagerPref1"
  71.     NbProg = ReadWord()
  72.  
  73.     For k=0 To NbProg-1
  74.       If AddElement(PL())
  75.         PL()\Item       = ReadString()
  76.         PL()\Command    = ReadString()
  77.         PL()\Processors = ReadByte()
  78.         PL()\Rendering  = ReadByte()
  79.         PL()\Warp3D     = ReadByte()
  80.         PL()\Width      = ReadWord()
  81.         PL()\Height     = ReadWord()
  82.         PL()\ScreenID   = ReadLong()
  83.         PL()\AGA        = ReadByte()
  84.       EndIf
  85.  
  86.       a$ = ReadString() ; "WAM_End_WAM"
  87.     Next
  88.  
  89.   EndIf
  90.  
  91.   CloseFile(0)
  92. Else
  93.   NoPref = 1
  94. EndIf
  95.  
  96. If NbProg<1 OR NoPref
  97.   AddElement(PL())
  98.   PL()\Item = "Program 1"
  99.   NbProg = 1
  100. EndIf
  101.  
  102. FirstElement(PL())
  103.  
  104. Dim Language.s(8)
  105.  
  106. *MyScreen = FindScreen(0,"Workbench")
  107.  
  108. ;
  109. ; Now, create all the windows gadgets
  110. ;
  111.  
  112. If CreateGadgetList(0, ScreenID())
  113.  
  114.   HG     = 20
  115.   HFont  = ScreenFontHeight()
  116.   HFont3 = HFont+3
  117.   HFont6 = HFont+6
  118.  
  119.   Top = HG
  120.  
  121.   StringGadget(1, 210, HG, 200, HFont6, "Name:"   , PL()\Item   , 0) : HG=HG+HFont6+2
  122.   StringGadget(2, 210, HG, 180, HFont6, "Program:", PL()\Command, 0)
  123.  
  124.   ButtonGadget(16,  390, HG, 20, HFont6, "?"   , 0) : HG=HG+HFont6+10
  125.  
  126.   Dim WildProcessor.s(2)
  127.   WildProcessor(0) = "680x0"
  128.   WildProcessor(1) = "PowerPC"
  129.  
  130.   ResetTagList (#GTCY_Active, PL()\Processors)
  131.   CycleGadget  (7, 210, HG, 100, HFont6, "Amiga :", WildProcessor(), *TagList) : HG=HG+HFont6+2
  132.  
  133.   Dim WildRender.s(4)
  134.   WildRender(0) = "WireFrame"
  135.   WildRender(1) = "Flat"
  136.   WildRender(2) = "Gouraud"
  137.   WildRender(3) = "Textured"
  138.  
  139.   ResetTagList (#GTCY_Active, PL()\Rendering)
  140.   CycleGadget  (8, 210, HG, 100, HFont6, "Rendering:", WildRender(), *TagList) : HG=HG+HFont6+2
  141.                                                                                                                               
  142.   ResetTagList  (#GTCB_Scaled, 1)
  143.         AddTag  (#GTCB_Checked, PL()\Warp3D)
  144.   CheckBoxGadget(13, 210, HG, HFont6, HFont6, "Warp3D", *TagList) : HG=HG+HFont6+2
  145.  
  146.   TextGadget(20,  330, HG,  80, HFont6, "" , 0)
  147.  
  148.   Dim WildScreen.s(2)
  149.   WildScreen(0) = "CGFX"
  150.   WildScreen(1) = "AGA"
  151.  
  152.   ResetTagList (#GTCY_Active, PL()\AGA)
  153.   CycleGadget  (21,  210, HG, 60, HFont6, "Screen :", WildScreen(), *TagList)
  154.   ButtonGadget (10,  272, HG, 50, HFont6, "Set", 0) : HG=HG+HFont6+HFont
  155.  
  156.   If PL()\Command = ""
  157.     a=1
  158.   Else
  159.     a=0
  160.   Endif
  161.  
  162.   ResetTagList (#GA_Disabled, a)
  163.   ButtonGadget (17,  210, HG, 200, HFont6, "-> Launch IT ! <-"   , *TagList)
  164.  
  165.   *RealList = ListBase(PL())
  166.  
  167.   ResetTagList   (#GTLV_ShowSelected, 0)
  168.         AddTag   (#GTLV_Selected, 0)
  169.   *a.Gadget = ListViewGadget(9, 12, Top+HFont+7, 100, HG-Top-(HFont+7), "Programs:", *RealList, *TagList)
  170.  
  171.   real = Top+HFont+9+*a\Height
  172.  
  173.   ButtonGadget   (14,  12, real, 49, HFont6, "Add", 0)
  174.   ButtonGadget   (15,  63, real, 49, HFont6, "Del", 0) : HG=HG+HFont6+16
  175.  
  176.   ButtonGadget   (4,  12, HG, 125, HFont6+2, "Save"   , 0)
  177.   ButtonGadget   (5, 148, HG, 125, HFont6+2, "Use"    , 0)
  178.   ButtonGadget   (6, 285, HG, 125, HFont6+2, "Cancel" , 0)
  179.  
  180. EndIf
  181.  
  182. ;
  183. ; Open our window and attach gadgets & menus..
  184. ;
  185.  
  186. WinTitle$    = "Wild Manager V1.00"
  187. ScreenTitle$ = "Wild Manager - © 1999 Fantaisie Software"
  188.  
  189. ResetTagList (#WA_Title, @WinTitle$)
  190.       AddTag (#WA_CustomScreen, ScreenID())
  191.       AddTag (#WA_ScreenTitle, @ScreenTitle$)
  192.  
  193. ChangeIDCMP(#IDCMP_MOUSEMOVE | #LISTVIEWIDCMP | #IDCMP_CLOSEWINDOW | #IDCMP_GADGETUP | #IDCMP_GADGETDOWN | #IDCMP_MOUSEBUTTONS |#IDCMP_VANILLAKEY|#IDCMP_MENUPICK)
  194.  
  195. WHeight = HG+HFont+2
  196. If OpenWindow(0, ScreenWidth()/2-210, HFont+20, 416, WHeight, #WFLG_CLOSEGADGET | #WFLG_DRAGBAR | #WFLG_DEPTHGADGET | #WFLG_ACTIVATE | #WFLG_RMBTRAP, *TagList)
  197.  
  198.   BevelBox(WindowBorderLeft(),WindowBorderTop(),WindowInnerWidth(),WindowInnerHeight(),0)
  199.  
  200.   BevelBox(WindowBorderLeft()-1,HG-7,WindowInnerWidth()+2,2,1)
  201.  
  202.   AttachGadgetList(0, WindowID())
  203.  
  204.   Gosub DisableWarp3D
  205.   Gosub DisableDel
  206.  
  207.   Gosub RefreshScreenMode
  208.  
  209. MainLoop:
  210.   Repeat
  211.  
  212.     Repeat
  213.       VWait()
  214.       IDCMP.l = WindowEvent()
  215.     Until IDCMP
  216.  
  217.     ; Special for mouseclick when editing a String !
  218.     ;
  219.     ;
  220.     If MustBeRefreshed
  221.       If MustBeRefreshed = 1
  222.         Gosub String1
  223.       Else
  224.         Gosub String2
  225.       EndIf
  226.  
  227.       MustBeRefreshed = 0
  228.     EndIf
  229.  
  230.  
  231.     Gadget = EventGadget()
  232.     Code   = EventCode()
  233.  
  234.     If IDCMP = #IDCMP_GADGETUP OR IDCMP = #IDCMP_GADGETDOWN ; A gadget has been pushed
  235.  
  236.       Select Gadget
  237.         Case 1
  238.           Gosub String1
  239.           MustBeRefreshed = 1
  240.  
  241.  
  242.         Case 2
  243.           Gosub String2
  244.           MustBeRefreshed = 2
  245.  
  246.  
  247.         Case 4 ; 'Save'
  248.           Gosub SavePrefs
  249.           IDCMP = #IDCMP_CLOSEWINDOW
  250.  
  251.  
  252.         Case 5 ; 'Use'
  253.           IDCMP = #IDCMP_CLOSEWINDOW
  254.  
  255.  
  256.         Case 6 ; 'Cancel'
  257.           IDCMP = #IDCMP_CLOSEWINDOW
  258.  
  259.  
  260.         Case 7
  261.           PL()\Processors = Code
  262.           PL()\Changed = 1
  263.  
  264.  
  265.         Case 8
  266.           PL()\Rendering = Code
  267.           PL()\Changed = 1
  268.  
  269.           Gosub DisableWarp3D
  270.  
  271.  
  272.         Case 9
  273.           ResetList(PL())
  274.  
  275.           For k=0 To Code
  276.             NextElement(PL())
  277.           Next
  278.  
  279.           Gosub RefreshWindow
  280.  
  281.  
  282.         Case 10
  283.  
  284.           ResetTagList (#ASLSM_DoWidth          , 1)
  285.                 AddTag (#ASLSM_DoHeight         , 1)
  286.                 AddTag (#ASLSM_DoOverscanType   , 1)
  287.                 AddTag (#ASLSM_InitialDisplayID , PL()\ScreenID)
  288.                 If PL()\Width
  289.                   AddTag (#ASLSM_InitialDisplayWidth  , PL()\Width)
  290.                   AddTag (#ASLSM_InitialDisplayHeight , PL()\Height)
  291.                 EndIf
  292.  
  293.           *sm.PBScreenInfo = ScreenRequester(*TagList)
  294.           If *sm
  295.             PL()\Width    = *sm\Width
  296.             PL()\Height   = *sm\Height
  297.             PL()\ScreenID = *sm\DisplayID
  298.           EndIf
  299.  
  300.           Gosub RefreshScreenMode
  301.  
  302.           PL()\Changed = 1
  303.  
  304.  
  305.         Case 13 ; 'Warp3D - On/Off'
  306.           PL()\Warp3D = Code
  307.           PL()\Changed = 1
  308.  
  309.  
  310.         Case 14 ; 'Add'
  311.  
  312.           NbProg = NbProg+1
  313.           AddElement(PL())
  314.           PL()\Item = ""
  315.  
  316.           GadgetAttrs(9, #GTLV_Labels, *RealList)
  317.           GadgetAttrs(9, #GTLV_Selected, ListIndex(PL()))
  318.  
  319.           RefreshGadget(9)
  320.           Gosub RefreshWindow
  321.  
  322.           ActivateGadget(1)
  323.  
  324.  
  325.         Case 15 ; 'Del'
  326.           KillElement(PL())
  327.  
  328.           NbProg = NbProg-1
  329.  
  330.           GadgetAttrs(9, #GTLV_Labels, *RealList)
  331.           RefreshGadget(9)
  332.           NextElement(PL())
  333.           Gosub RefreshWindow
  334.  
  335.  
  336.         Case 16
  337.  
  338.           b$ = PL()\Command
  339.  
  340.           file$ = GetFilePart(b$)
  341.           path$ = GetPathPart(b$)
  342.  
  343.           ResetTagList (#ASLFR_InitialTopEdge , WindowY()+WindowBorderTop())
  344.                 AddTag (#ASLFR_InitialLeftEdge, WindowX())
  345.                 AddTag (#ASLFR_InitialHeight  , ScreenHeight()/2)
  346.                 AddTag (#ASLFR_InitialWidth   , 200)
  347.                 AddTag (#ASLFR_InitialFile    , file$)
  348.                 AddTag (#ASLFR_InitialDrawer  , path$)
  349.  
  350.           ; STOP
  351.  
  352.           a$ = FileRequester(*TagList)
  353.  
  354.           If a$ <> ""
  355.             SetStringText(2, a$)
  356.             RefreshGadget(2)
  357.             Gosub String2
  358.           EndIf
  359.  
  360.  
  361.         Case 17 ; 'Launch IT !'
  362.           Gosub SetPref
  363.           PL()\Changed = 0
  364.  
  365.           b$ = GetPathPart(PL()\Command)
  366.  
  367.           RunProgram(b$, Chr(34)+PL()\Command+Chr(34), 1, 8192)
  368.  
  369.         Case 21 ; 'AGA - CGFX'
  370.           PL()\AGA = Code
  371.           PL()\Changed = 1
  372.  
  373.  
  374.       EndSelect
  375.     EndIf
  376.  
  377.   Until IDCMP = #IDCMP_CLOSEWINDOW
  378.  
  379. EndIf
  380.  
  381. End
  382.  
  383.  
  384. RefreshWindow:
  385.  
  386.   Gosub DisableDel
  387.  
  388.   Gosub DisableWarp3D
  389.  
  390.   Gosub RefreshScreenMode
  391.  
  392.   SetStringText(1, PL()\Item)
  393.   SetStringText(2, PL()\Command)
  394.  
  395.   If PL()\Command<>""
  396.     DisableGadget(17, 0)
  397.   Else
  398.     DisableGadget(17, 1)
  399.   Endif
  400.  
  401.   GadgetAttrs (7, #GTCY_Active, PL()\Processors)
  402.   GadgetAttrs (8, #GTCY_Active, PL()\Rendering)
  403.   GadgetAttrs (21,#GTCY_Active, PL()\AGA)
  404.  
  405.   GadgetAttrs (13,#GTCB_Checked, PL()\Warp3D)
  406.  
  407.   RefreshGadget(1)
  408.   RefreshGadget(2)
  409.   RefreshGadget(7)
  410.   RefreshGadget(8)
  411.  
  412. Return
  413.  
  414.  
  415. SavePrefs:
  416.   If CreateFile(0,"PROGDIR:WildManager.pref")
  417.  
  418.     WriteString("WildManagerPref1")
  419.     WriteWord(NbProg)
  420.  
  421.     ResetList(PL())
  422.  
  423.     For k=0 To NbProg-1
  424.       If NextElement(PL())
  425.         WriteString(PL()\Item)
  426.         WriteString(PL()\Command)
  427.  
  428.         WriteByte(PL()\Processors)
  429.         WriteByte(PL()\Rendering)
  430.         WriteByte(PL()\Warp3D)
  431.  
  432.         WriteWord(PL()\Width)
  433.         WriteWord(PL()\Height)
  434.         WriteLong(PL()\ScreenID)
  435.         WriteByte(PL()\AGA)
  436.       EndIf
  437.  
  438.       WriteString("WAM_End_WAM")
  439.     Next
  440.  
  441.     CloseFile(0)
  442.   EndIf
  443.  
  444.   ResetList(PL())
  445.  
  446.   For k=0 To NbProg-1
  447.     If NextElement(PL())
  448.       If PL()\Changed
  449.         Gosub SetPref
  450.       EndIf
  451.     EndIf
  452.   Next
  453.  
  454. Return
  455.  
  456.  
  457. DisableDel:
  458.  
  459.   If CountList(PL()) = 1
  460.     DisableGadget(15, 1)
  461.   Else
  462.     DisableGadget(15, 0)
  463.   EndIf
  464.  
  465. Return
  466.  
  467.  
  468. DisableWarp3D:
  469.  
  470.   If PL()\Rendering<>3
  471.     DisableGadget(13, 1)
  472.   Else
  473.     DisableGadget(13, 0)
  474.   EndIf
  475.  
  476. Return
  477.                                                                                                                               
  478.  
  479.  
  480. String1:
  481.   PL()\Item = GetStringText(1)
  482.   GadgetAttrs(9, #GTLV_Labels, *RealList)
  483.   RefreshGadget(9)
  484. Return
  485.  
  486.  
  487. String2:
  488.   PL()\Command = GetStringText(2)
  489.  
  490.   If PL()\Command<>""
  491.     DisableGadget(17, 0)
  492.   Else
  493.     DisableGadget(17, 1)
  494.   EndIf
  495.  
  496.   RefreshGadget(17)
  497.  
  498.   PL()\Changed = 1
  499.  
  500. Return
  501.  
  502.  
  503. SetPref:
  504.  
  505.   If PL()\Processors = 0
  506.  
  507.     Param$ = "TD Monkey"
  508.  
  509.     If PL()\Rendering = 0 ; Special case for WireFrame
  510.       Param$ = Param$ + " DI TryZkren"
  511.     Else
  512.  
  513.       If PL()\AGA
  514.         Param$ = Param$ + " DI TryPeJam+"
  515.       Else
  516.         Param$ = Param$ + " DI Cyborg"
  517.       EndIf
  518.  
  519.     EndIf
  520.  
  521.  
  522.     Select PL()\Rendering
  523.  
  524.       Case 0 ; 'Wire'
  525.         Param$ = Param$ + " DW Wire BK no LI no"
  526.  
  527.       Case 1 ; 'Flat'
  528.         Param$ = Param$ + " DW Flat BK NiX+ LI Flash"
  529.  
  530.       Case 2 ; 'Gouraud'
  531.         Param$ = Param$ + " DW Fluff BK ShiX LI Torch"
  532.  
  533.       Case 3 ; 'Textured'
  534.         Param$ = Param$ + " DW Candy+ BK TiX+ LI Torch"
  535.  
  536.     EndSelect
  537.  
  538.   Else
  539.  
  540.     Param$ = "TD Evolution"
  541.  
  542.     If PL()\Rendering = 0 ; Special case for WireFrame
  543.       Param$ = Param$ + " DI TryZkren"
  544.     Else
  545.  
  546.       If PL()\AGA
  547.         Param$ = Param$ + " DI TryNoe8"
  548.       Else
  549.         Param$ = Param$ + " DI Cyborg"
  550.       EndIf
  551.  
  552.     EndIf
  553.  
  554.  
  555.     Select PL()\Rendering
  556.  
  557.       Case 0 ; 'Wire'
  558.         Param$ = Param$ + " DW Wire BK no LI no"
  559.  
  560.       Case 1 ; 'Flat'
  561.         Param$ = Param$ + " DW Flat BK NiX+ LI Flash"
  562.  
  563.       Case 2 ; 'Gouraud'
  564.         Param$ = Param$ + " DW Fluff BK ShiX LI WTorch"
  565.  
  566.       Case 3 ; 'Textured'
  567.         Param$ = Param$ + " DW PowerDragon BK WTiX LI WTorch"
  568.  
  569.     EndSelect
  570.  
  571.   EndIf
  572.  
  573.  
  574.   If PL()\Warp3D
  575.     If PL()\Processors = 0
  576.       Param$ = "TD Monkey LI Torch"
  577.     Else
  578.       Param$ = "TD Evolution LI WTorch"
  579.     EndIf
  580.  
  581.     Param$ = Param$ + " DW DrScott DI CyborgHi BK no"
  582.   EndIf
  583.  
  584.  
  585.   If PL()\Width
  586.     Param$ = Param$+" WID "+Str(PL()\Width)+" HEI "+Str(PL()\Height);+" MODEID $";+Hex$(\ScreenID)
  587.   EndIf
  588.  
  589.   c$ = GetFilePart(PL()\Command)
  590.  
  591.   If c$ <> ""
  592.     RunProgram("WildPJ:Tools", "CloseWild", 0, 4096)
  593.     RunProgram("WildPJ:Tools", "SetWildAppPrefs "+c$+" save "+Param$, 0, 4096)
  594.   EndIf
  595.  
  596. Return
  597.  
  598.  
  599. RefreshScreenMode:
  600.  
  601.   If PL()\Width
  602.     Mode = Str(PL()\Width)+"x"+Str(PL()\Height)
  603.   Else
  604.     Mode = "Default"
  605.   EndIf
  606.  
  607.   GadgetAttrs(20, #GTTX_Text, Mode)
  608.   RefreshGadget(20)
  609.  
  610. Return
  611.  
  612.